# -*- coding:UTF-8 -*-

import ConnMySql
import ConnES
import ConnRedis
import ConnMongo
import yaml

class dbInit:
    def __init__(self, strconfig):
        self.fr = open('Config.yml', 'r')
        self.fconfig = yaml.load(self.fr)
        self.strconfig = strconfig
        self.realConfig = self.fconfig[self.strconfig]

    def initMysql(self,value):
        self.value = value
        memsum = self.realConfig[self.value]
        host = memsum["host"]
        user = memsum["user"]
        pwd = memsum["password"]
        name = memsum["name"]
        port = memsum["port"]
        charset = memsum["charset"]
        return ConnMySql.ConnMySql(host, port, name, user, pwd, charset)

    def initRedis(self,value):
        self.value = value
        rediss = self.realConfig["redis"]
        host = rediss["host"]
        port = rediss["port"]
        name = rediss[self.value]
        pwd = rediss["password"]
        return ConnRedis.ConnRedis(host, port, name, pwd)

    def initES(self):
        ess = self.realConfig["es"]
        host = ess["host"]
        port = ess["port"]
        index = ess["index"]
        return ConnES.ConnES(host, port, index)

    def initMonogo(self,value):
        self.value = value
        monogo = self.realConfig[self.value]
        host = monogo["host"]
        port = monogo["port"]
        dbname = monogo["dbname"]
        tbname = monogo["tbname"]
        monUser = monogo["user"]
        monPwd = monogo["pwd"]
        return ConnMongo.ConnMongo(host, port, dbname, tbname, monUser, monPwd)

    def httpurl(self):
        return self.realConfig["removecellphone"]

    def deletekey(self):
        return self.realConfig["deletekey"]

    def deleteorderurl(self):
        return self.realConfig["deleteorderurl"]